var orderList = {};
var OrderList = function () {
    this.dictMap = {}; //数据字典
    //初始化函数
    this.init = function () {
        //初始化数据字典
        layuiFunciton.ajaxRequest({
            url: layuiFunciton.URL + '/sys/dictVal/getByTypeCode',
            method: 'get',
            maskState: false,
            success: function (data) {
                data.forEach(function (obj, index) {
                    orderList.dictMap[obj.valCode] = obj.valName;
                });
            }
        });
        //初始化表格
        layuiFunciton.tableInit({
            toolbar: false,
            tableId: 'orderListTableId',
            url: layuiFunciton.URL + '/wb/sterilisation/records/findOrderBySettlementNumber',
            id: 'orderListId',
            page: false,
            searchFromId: 'formOrder',
            totalRow: true,
            tableFilter: 'orderListFilter',  //表格监听名称,
            cols: [[
                , {field: 'orderDate', title: '下单日期', sort: true}
                , {field: 'dateShipment', title: '发运日期', sort: true}
                , {
                    field: 'businessTypes', title: '业务类型', sort: true,
                    templet: function (row) {
                        return orderList.dictMap[row.businessTypes]?orderList.dictMap[row.businessTypes]:'';
                    }
                }
                , {
                    field: 'ofTheGoods', title: '品名', sort: true,
                    templet: function (row) {
                        return orderList.dictMap[row.ofTheGoods]?orderList.dictMap[row.ofTheGoods]:'';
                    }
                }
                , {
                    field: 'aBox', title: '箱型', sort: true,
                    templet: function (row) {
                        return orderList.dictMap[row.aBox]?orderList.dictMap[row.aBox]:'';
                    }
                }
                , {field: 'cartonNo', title: '箱号', sort: true}
                , {
                    field: 'receivingUnit', title: '收货人', sort: true/*,
                     templet: function (row) {
                     return orderList.dictMap[row.receivingUnit];
                     }*/
                }
                , {
                    field: 'settlementPeople', title: '结算人', sort: true,
                    templet: function (row) {
                        return orderList.dictMap[row.settlementPeople];
                    }
                }
                , {
                    field: 'accountsReceivableAmount', title: '应收金额', sort: true,
                    totalRowText: '<span style="color: green" class="accountsReceivableAmount">0.00</span>',
                    templet: function (row) {
                        return Number(row.accountsReceivableAmount).toFixed(2);
                    }
                }, {
                    field: 'sterilisationAmount', title: '核销金额', sort: true,
                    totalRowText: '<span style="color: green" class="sterilisationAmount">0.00</span>',
                    templet: function (row) {
                        return Number(row.sterilisationAmount).toFixed(2);
                    }
                }
            ]],
            returnData: function (res) {
                var accountsReceivableAmount = 0.00, sterilisationAmount = 0.00;
                res.forEach(function (obj, index) {
                    accountsReceivableAmount = (Number(accountsReceivableAmount) + Number(obj.accountsReceivableAmount)).toFixed(2);
                    sterilisationAmount = (Number(sterilisationAmount) + Number(obj.sterilisationAmount)).toFixed(2);
                });
                $(".accountsReceivableAmount").html(accountsReceivableAmount);
                $(".sterilisationAmount").html(sterilisationAmount);
            }
        });
    };
};
function pageReady() {
    orderList = new OrderList();
    orderList.init();
}
